//
//  UIViewController+Link.m
//  XPhoto
//
//  Created by sentinel on 2020/3/31.
//  Copyright © 2020 baboy. All rights reserved.
//

#import "UIViewController+Link.h"
#import "UserProfileViewController.h"
#import "TopicPostViewController.h"
#import "BKWebViewController.h"
#import <BKKit/BKNavigationController.h>

@interface UIViewController (_Link)

@end

@implementation UIViewController(Link)
- (BOOL)openLink:(NSURL *)URL{
    if ([[URL scheme] isEqualToString:APP_LINK_SCHEME]) {
        //点击喜欢人数标签
       if( [[URL host] isEqualToString:APP_LINK_TYPE_LIKE] ){
       }
       //点击评论数标签
       if( [[URL host] isEqualToString:APP_LINK_TYPE_COMMENT] ){
       }
       //点击话题
       if( [[URL host] isEqualToString:APP_LINK_TYPE_TOPIC] ){
           TopicPostViewController *vc = [[TopicPostViewController alloc] init];
           vc.topic = [URL lastPathComponent];
           [self.navigationController pushViewController:vc animated:YES];
           return YES;
           
       }
       //点击@对象
       if( [[URL host] isEqualToString:APP_LINK_TYPE_USER] ){
           NSInteger uid = [[URL lastPathComponent] intValue];
           UserProfileViewController *vc = [[UserProfileViewController alloc] init];
           vc.uid = uid;
           [self.navigationController pushViewController:vc animated:YES];
           return YES;
       }
        return NO;
    }
    if ([[URL scheme] isEqualToString:@"http"] || [[URL scheme] isEqualToString:@"https"]) {
        BKWebViewController *vc = [[BKWebViewController alloc] init];
        vc.currentURL = URL;
        BKNavigationController *nav = [[BKNavigationController alloc] initWithRootViewController:vc];
        nav.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:nav animated:YES completion:^{
            
        }];
    }
    return NO;
}

@end
